package com.example.controller;
import com.example.common.Result;
import com.example.pojo.Room;
import com.example.pojo.RoomImage;
import com.example.pojo.RoomType;
import com.example.service.RoomImageService;
import com.example.service.RoomService;
import com.example.service.RoomTypeService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roomType")
public class RoomTypeController {
    @Resource
    private RoomTypeService roomTypeService;


    /**
     * 添加房间分类
     * @param roomType
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody RoomType roomType) {
        roomTypeService.add(roomType);

        return Result.success(roomType);
    }

    /**
     * 修改房间
     * @param roomType
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody RoomType roomType) {
        roomTypeService.updateById(roomType);
        return Result.success();
    }

    /**
     * 删除房间
     * @return
     */
    @DeleteMapping("/delete")
    public Result deleteById(@RequestParam Integer id) {
        roomTypeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除房间
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        roomTypeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 查询所有房间
     *
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(RoomType roomType) {
        List<RoomType> list = roomTypeService.selectAll(roomType);
        return Result.success(list);
    }



    /**@PathVariable的查询方式/selectById/1(/..)
     * 根据id查询用户
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        RoomType roomType = roomTypeService.selectById(id);
        return Result.success(roomType);
    }

    /**@RequestParam的查询方式/selectPage?pageNum=1(&...=...)
     * @RequestParam(defaultValue = "1")默认值为1
     *@RequestParam(required = false)不是必须要传参
     * 分页查询
     */
    @GetMapping("/SelectPage")
    public Result selectPage(RoomType roomType,@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<RoomType> pageInfo= roomTypeService.selectPage(roomType,pageNum,pageSize);
        return Result.success(pageInfo);
    }
}
